using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using GonzalesCore.CoreElements;

using Kypris2.CoreElements;

using Jamila2.CoreElements;
using Jamila2.Database;
using Jamila2.Tools;

namespace GonzalesCore.CoreManagers
{
    public enum LogInterface { System, User };

    public class LogManager : SystemLogger, IManager, IDisposable
    {
        protected PersonalSessionAccount CurrentPrivateSession = null; // Thang Nguyen added 07/03/2013
        private GonzalesDataStructure DataStructure = new GonzalesDataStructure();
        
        public bool IsReady = false;
        public string Conn = "";

        public SQLFactory CurSQLFactory = null;
        public TypeOfDatabase DBType = TypeOfDatabase.MSSQL;

        private string ErrMsg = "";
        public virtual string ErrorMessage
        {
            get
            {
                return this.ErrMsg;
            }
        }

        public LogManager(Jamila2.Database.TypeOfDatabase DBType, string Conn)
            : base(DBType, Conn)
        {
            this.DBType = DBType;
            this.Conn = Conn;
        }

        public LogManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.DBType = PrivateConfig.DatabaseType;
            this.Conn = PrivateConfig.DatabaseConnectionString;
            CurrentPrivateSession = PrivateConfig;
        }

        #region Display

        #region GetActionLogByClaimID

        public LogsCollection GetActionLogByClaimID(string InternalID)
        {
            LogsCollection ResultCollection = null;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                //KeyParameters.Add(new DatabaseParameter(this.DataStructure.Views.ActionHistory.ClaimID.ActualFieldName, InternalID));
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.StoredProcedures.ActionHistory.Param_InternalID.ActualFieldName, InternalID));

                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructure.StoredProcedures.ActionHistory.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new LogsCollection();

                    DataRow[] ResultRows = ResultTable.Select("", this.DataStructure.Views.ActionHistory.ActionDateTime.ActualFieldName);

                    foreach (DataRow ResultRow in ResultRows)
                    {
                        ActionLogItem CurLogItem = new ActionLogItem();
                        CurLogItem.ClaimInternalID = ResultRow[this.DataStructure.Views.ActionHistory.ClaimID.ActualFieldName].ToString();
                        CurLogItem.LogDate = Convert.ToDateTime(ResultRow[this.DataStructure.Views.ActionHistory.ActionDateTime.ActualFieldName]);
                        CurLogItem.LoggedBy = new SystemUser(
                            ResultRow[this.DataStructure.Views.ActionHistory.PersonnelID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructure.Views.ActionHistory.EmployeeDisplayName.ActualFieldName].ToString());
                        CurLogItem.LoggedBy.EmailID = ResultRow[this.DataStructure.Views.ActionHistory.EmailID.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.Email = ResultRow[this.DataStructure.Views.ActionHistory.Email.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.EmployeeID = ResultRow[this.DataStructure.Views.ActionHistory.EmployeeID.ActualFieldName].ToString();
                        CurLogItem.ActionStatus = ClaimManager.GetClaimStatusFromCode(ResultRow[this.DataStructure.Views.ActionHistory.ActionStatus.ActualFieldName].ToString());
                        CurLogItem.ActionDescription = ResultRow[this.DataStructure.Views.ActionHistory.Action.ActualFieldName].ToString();

                        ResultCollection.Add(CurLogItem);
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetActionLogByClaimID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultCollection;
        }

        #endregion

        #region GetActionLogByClaimIDClaimAction

        public LogsCollection GetActionLogByClaimIDClaimAction(string InternalID, string ClaimAction)
        {
            LogsCollection ResultCollection = null;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                //KeyParameters.Add(new DatabaseParameter(this.DataStructure.Views.ActionHistory.ClaimID.ActualFieldName, InternalID));
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.StoredProcedures.ActionHistory.Param_InternalID.ActualFieldName, InternalID));

                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructure.StoredProcedures.ActionHistory.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new LogsCollection();

                    DataRow[] ResultRows = ResultTable.Select("", this.DataStructure.Views.ActionHistory.ActionDateTime.ActualFieldName);

                    foreach (DataRow ResultRow in ResultRows)
                    {
                        if (ResultRow[this.DataStructure.Views.ActionHistory.Action.ActualFieldName].ToString().CompareTo(ClaimAction) == 0)
                        {
                            ActionLogItem CurLogItem = new ActionLogItem();
                            CurLogItem.ClaimInternalID = ResultRow[this.DataStructure.Views.ActionHistory.ClaimID.ActualFieldName].ToString();
                            CurLogItem.LogDate = Convert.ToDateTime(ResultRow[this.DataStructure.Views.ActionHistory.ActionDateTime.ActualFieldName]);
                            CurLogItem.LoggedBy = new SystemUser(
                                ResultRow[this.DataStructure.Views.ActionHistory.PersonnelID.ActualFieldName].ToString(),
                                ResultRow[this.DataStructure.Views.ActionHistory.EmployeeDisplayName.ActualFieldName].ToString());
                            CurLogItem.LoggedBy.EmailID = ResultRow[this.DataStructure.Views.ActionHistory.EmailID.ActualFieldName].ToString();
                            CurLogItem.LoggedBy.Email = ResultRow[this.DataStructure.Views.ActionHistory.Email.ActualFieldName].ToString();
                            CurLogItem.LoggedBy.EmployeeID = ResultRow[this.DataStructure.Views.ActionHistory.EmployeeID.ActualFieldName].ToString();
                            CurLogItem.ActionStatus = ClaimManager.GetClaimStatusFromCode(ResultRow[this.DataStructure.Views.ActionHistory.ActionStatus.ActualFieldName].ToString());
                            CurLogItem.ActionDescription = ResultRow[this.DataStructure.Views.ActionHistory.Action.ActualFieldName].ToString();

                            ResultCollection.Add(CurLogItem);
                        }
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetActionLogByClaimID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultCollection;
        }

        #endregion

        #region GetClaimActionLogCountByClaimID

        public int GetClaimActionLogCountByClaimID(string ClaimInternalID)
        {
            int Count = 0;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.Tables.LogClaimAction.ClaimInternalID.ActualFieldName, ClaimInternalID));

                this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructure.Tables.LogClaimAction.ActualTableName);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    if (ResultTable.Rows.Count > 0)
                    {
                        if (ResultTable.Rows[0][1].ToString().Length > 0)
                            Count = 1;
                        else if (ResultTable.Rows[0][5].ToString().Length > 0)
                            Count = 2;
                        else if (ResultTable.Rows[0][9].ToString().Length > 0)
                            Count = 3;
                        else if (ResultTable.Rows[0][13].ToString().Length > 0)
                            Count = 4;
                        else if (ResultTable.Rows[0][17].ToString().Length > 0)
                            Count = 5;
                        else if (ResultTable.Rows[0][21].ToString().Length > 0)
                            Count = 6;
                    }
                    else
                    {
                        Count = 0;
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetClaimActionLogCountByClaimID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return Count;
        }

        #endregion

        #region GetAllErrorLog

        public LogsCollection GetAllErrorLog(DateTime DateStart, DateTime DateEnd)
        {
            LogsCollection ResultCollection = null;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter("CONVERT(VARCHAR(8),"+this.DataStructure.Views.ErrorHistory.LogDateTime.ActualFieldName+", 112)", DateStart.ToString("yyyyMMdd"), DBDataType.String, DBLinkage.AND, DBCompareType.LargerNEqual));
                KeyParameters.Add(new DatabaseParameter("CONVERT(VARCHAR(8)," + this.DataStructure.Views.ErrorHistory.LogDateTime.ActualFieldName + ", 112)", DateEnd.ToString("yyyyMMdd"), DBDataType.String, DBLinkage.AND, DBCompareType.SmallerNEqual));

                this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructure.Views.ErrorHistory.ActualTableName);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new LogsCollection();

                    DataRow[] ResultRows = ResultTable.Select("", this.DataStructure.Views.ErrorHistory.LogDateTime.ActualFieldName);

                    foreach (DataRow ResultRow in ResultRows)
                    {
                        ErrorLogItem CurLogItem = new ErrorLogItem();

                        CurLogItem.LogID = ResultRow[this.DataStructure.Views.ErrorHistory.LogID.ActualFieldName].ToString();
                        CurLogItem.LogDate = Convert.ToDateTime(ResultRow[this.DataStructure.Views.ErrorHistory.LogDateTime.ActualFieldName]);
                        CurLogItem.LoggedBy = new SystemUser(
                            ResultRow[this.DataStructure.Views.ErrorHistory.EmployeeInternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructure.Views.ErrorHistory.EmployeeDisplayName.ActualFieldName].ToString());
                        CurLogItem.LoggedBy.EmailID = ResultRow[this.DataStructure.Views.ErrorHistory.EmailID.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.Email = ResultRow[this.DataStructure.Views.ErrorHistory.Email.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.EmployeeID = ResultRow[this.DataStructure.Views.ErrorHistory.EmployeeID.ActualFieldName].ToString();

                        CurLogItem.Description = ResultRow[this.DataStructure.Views.ErrorHistory.Description.ActualFieldName].ToString();

                        ResultCollection.Add(CurLogItem);
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetActionLogByClaimID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultCollection;
        }

        #endregion

        #region GetAllGeneralLog

        public LogsCollection GetAllGeneralLog()
        {
            LogsCollection ResultCollection = null;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();

                this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructure.Views.GeneralActionHistory.ActualTableName);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new LogsCollection();

                    DataRow[] ResultRows = ResultTable.Select("", this.DataStructure.Views.GeneralActionHistory.LogDateTime.ActualFieldName);

                    foreach (DataRow ResultRow in ResultRows)
                    {
                        GeneralActionLogItem CurLogItem = new GeneralActionLogItem();

                        CurLogItem.LogDate = Convert.ToDateTime(ResultRow[this.DataStructure.Views.GeneralActionHistory.LogDateTime.ActualFieldName]);
                        CurLogItem.LoggedBy = new SystemUser(
                            ResultRow[this.DataStructure.Views.GeneralActionHistory.EmployeeInternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructure.Views.GeneralActionHistory.EmployeeDisplayName.ActualFieldName].ToString());
                        CurLogItem.LoggedBy.EmailID = ResultRow[this.DataStructure.Views.GeneralActionHistory.EmailID.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.Email = ResultRow[this.DataStructure.Views.GeneralActionHistory.Email.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.EmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.EmployeeID.ActualFieldName].ToString();
                        CurLogItem.Description = ResultRow[this.DataStructure.Views.GeneralActionHistory.Description.ActualFieldName].ToString();

                        //Frank add jan-2013
                        //this one not correct
                        CurLogItem.Interface = (LogInterface)Enum.Parse(typeof(LogInterface), ResultRow[this.DataStructure.Views.GeneralActionHistory.Interface.ActualFieldName].ToString(), true);
                        CurLogItem.UserID = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserID.ActualFieldName].ToString();
                        CurLogItem.UserName = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserName.ActualFieldName].ToString();
                        CurLogItem.ClaimantID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantID.ActualFieldName].ToString();
                        CurLogItem.ClaimantName = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantName.ActualFieldName].ToString();
                        CurLogItem.RoleID = ResultRow[this.DataStructure.Views.GeneralActionHistory.RoleID.ActualFieldName].ToString();
                        CurLogItem.Action = ResultRow[this.DataStructure.Views.GeneralActionHistory.Action.ActualFieldName].ToString();
                        CurLogItem.ApproverID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ApproverID.ActualFieldName].ToString();
                        CurLogItem.ApproverName = ResultRow[this.DataStructure.Views.GeneralActionHistory.ApproverName.ActualFieldName].ToString();
                        CurLogItem.DfltCurrency = ResultRow[this.DataStructure.Views.GeneralActionHistory.DfltCurrency.ActualFieldName].ToString();

                        CurLogItem.CreditCardNo = ResultRow[this.DataStructure.Views.GeneralActionHistory.CreditCardNo.ActualFieldName].ToString();
                        CurLogItem.AprStopPoint = ResultRow[this.DataStructure.Views.GeneralActionHistory.AprStopPoint.ActualFieldName].ToString();
                        CurLogItem.AprLimit = ResultRow[this.DataStructure.Views.GeneralActionHistory.AprLimit.ActualFieldName].ToString();
                        CurLogItem.NoAprRq = ResultRow[this.DataStructure.Views.GeneralActionHistory.NoAprRq.ActualFieldName].ToString();
                        CurLogItem.NoAuthorizerRq = ResultRow[this.DataStructure.Views.GeneralActionHistory.NoAuthorizerRq.ActualFieldName].ToString();
                        CurLogItem.AprRoute = ResultRow[this.DataStructure.Views.GeneralActionHistory.AprRoute.ActualFieldName].ToString();

                        CurLogItem.AsClaimant = ResultRow[this.DataStructure.Views.GeneralActionHistory.AsClaimant.ActualFieldName].ToString();
                        CurLogItem.AsReviewer = ResultRow[this.DataStructure.Views.GeneralActionHistory.AsReviewer.ActualFieldName].ToString();
                        CurLogItem.LDAPAddress = ResultRow[this.DataStructure.Views.GeneralActionHistory.LDAPAddress.ActualFieldName].ToString();
                        CurLogItem.AprRangeFr = double.Parse(ResultRow[this.DataStructure.Views.GeneralActionHistory.AprRangeFr.ActualFieldName].ToString());
                        CurLogItem.AprRangeTo = double.Parse(ResultRow[this.DataStructure.Views.GeneralActionHistory.AprRangeTo.ActualFieldName].ToString());
                        CurLogItem.LogType = ResultRow[this.DataStructure.Views.GeneralActionHistory.LogType.ActualFieldName].ToString();
                        CurLogItem.AprLevel = int.Parse(ResultRow[this.DataStructure.Views.GeneralActionHistory.AprLevel.ActualFieldName].ToString());

                        CurLogItem.UserEmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserEmployeeID.ActualFieldName].ToString();
                        CurLogItem.UserEntity = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserEntity.ActualFieldName].ToString();
                        CurLogItem.ClaimantEmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantEmployeeID.ActualFieldName].ToString();
                        CurLogItem.ClaimantCompany = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantCompany.ActualFieldName].ToString();
                        CurLogItem.ApproverEmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ApproverEmployeeID.ActualFieldName].ToString();

                        ResultCollection.Add(CurLogItem);
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetAllGeneralLog] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultCollection;
        }

        // Thang Nguyen added 07032013: Get all general log with parametters
        public LogsCollection GetAllGeneralLog(string From_LogDateTime, string To_LogDateTime, string PersonnelName, string LogType)
        {
            LogsCollection ResultCollection = null;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters(); 
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.StoredProcedures.GetAllGeneralLog.para_FromLogDateTime.ActualFieldName, From_LogDateTime));
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.StoredProcedures.GetAllGeneralLog.para_ToLogDateTime.ActualFieldName, To_LogDateTime));
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.StoredProcedures.GetAllGeneralLog.para_PersonnelName.ActualFieldName, PersonnelName));
                KeyParameters.Add(new DatabaseParameter(this.DataStructure.StoredProcedures.GetAllGeneralLog.para_LogType.ActualFieldName, LogType));

                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructure.StoredProcedures.GetAllGeneralLog.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultCollection = new LogsCollection();

                    DataRow[] ResultRows = ResultTable.Select("", this.DataStructure.Views.GeneralActionHistory.LogDateTime.ActualFieldName);

                    foreach (DataRow ResultRow in ResultRows)
                    {
                        GeneralActionLogItem CurLogItem = new GeneralActionLogItem();
                        
                        CurLogItem.LogDate = Convert.ToDateTime(ResultRow[this.DataStructure.Views.GeneralActionHistory.LogDateTime.ActualFieldName]);
                        CurLogItem.LoggedBy = new SystemUser(
                            ResultRow[this.DataStructure.Views.GeneralActionHistory.EmployeeInternalID.ActualFieldName].ToString(),
                            ResultRow[this.DataStructure.Views.GeneralActionHistory.EmployeeDisplayName.ActualFieldName].ToString());
                        CurLogItem.LoggedBy.EmailID = ResultRow[this.DataStructure.Views.GeneralActionHistory.EmailID.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.Email = ResultRow[this.DataStructure.Views.GeneralActionHistory.Email.ActualFieldName].ToString();
                        CurLogItem.LoggedBy.EmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.EmployeeID.ActualFieldName].ToString();
                        CurLogItem.Description = ResultRow[this.DataStructure.Views.GeneralActionHistory.Description.ActualFieldName].ToString();

                        //Frank add jan-2013
                        //this one not correct
                        CurLogItem.Interface = (LogInterface)Enum.Parse(typeof(LogInterface), ResultRow[this.DataStructure.Views.GeneralActionHistory.Interface.ActualFieldName].ToString(),true);
                        CurLogItem.UserID = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserID.ActualFieldName].ToString();
                        CurLogItem.UserName = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserName.ActualFieldName].ToString();
                        CurLogItem.ClaimantID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantID.ActualFieldName].ToString();
                        CurLogItem.ClaimantName = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantName.ActualFieldName].ToString();
                        CurLogItem.RoleID = ResultRow[this.DataStructure.Views.GeneralActionHistory.RoleID.ActualFieldName].ToString();
                        CurLogItem.Action = ResultRow[this.DataStructure.Views.GeneralActionHistory.Action.ActualFieldName].ToString();
                        CurLogItem.ApproverID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ApproverID.ActualFieldName].ToString();
                        CurLogItem.ApproverName = ResultRow[this.DataStructure.Views.GeneralActionHistory.ApproverName.ActualFieldName].ToString();
                        CurLogItem.DfltCurrency = ResultRow[this.DataStructure.Views.GeneralActionHistory.DfltCurrency.ActualFieldName].ToString();

                        CurLogItem.CreditCardNo = ResultRow[this.DataStructure.Views.GeneralActionHistory.CreditCardNo.ActualFieldName].ToString();
                        CurLogItem.AprStopPoint = ResultRow[this.DataStructure.Views.GeneralActionHistory.AprStopPoint.ActualFieldName].ToString();
                        CurLogItem.AprLimit = ResultRow[this.DataStructure.Views.GeneralActionHistory.AprLimit.ActualFieldName].ToString();
                        CurLogItem.NoAprRq = ResultRow[this.DataStructure.Views.GeneralActionHistory.NoAprRq.ActualFieldName].ToString();
                        CurLogItem.NoAuthorizerRq = ResultRow[this.DataStructure.Views.GeneralActionHistory.NoAuthorizerRq.ActualFieldName].ToString();
                        CurLogItem.AprRoute = ResultRow[this.DataStructure.Views.GeneralActionHistory.AprRoute.ActualFieldName].ToString();

                        CurLogItem.AsClaimant = ResultRow[this.DataStructure.Views.GeneralActionHistory.AsClaimant.ActualFieldName].ToString();
                        CurLogItem.AsReviewer = ResultRow[this.DataStructure.Views.GeneralActionHistory.AsReviewer.ActualFieldName].ToString();
                        CurLogItem.LDAPAddress = ResultRow[this.DataStructure.Views.GeneralActionHistory.LDAPAddress.ActualFieldName].ToString();
                        CurLogItem.AprRangeFr = double.Parse(ResultRow[this.DataStructure.Views.GeneralActionHistory.AprRangeFr.ActualFieldName].ToString());
                        CurLogItem.AprRangeTo = double.Parse(ResultRow[this.DataStructure.Views.GeneralActionHistory.AprRangeTo.ActualFieldName].ToString());
                        CurLogItem.LogType = ResultRow[this.DataStructure.Views.GeneralActionHistory.LogType.ActualFieldName].ToString();
                        CurLogItem.AprLevel = int.Parse(ResultRow[this.DataStructure.Views.GeneralActionHistory.AprLevel.ActualFieldName].ToString());

                        CurLogItem.UserEmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserEmployeeID.ActualFieldName].ToString();
                        CurLogItem.UserEntity = ResultRow[this.DataStructure.Views.GeneralActionHistory.UserEntity.ActualFieldName].ToString();
                        CurLogItem.ClaimantEmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantEmployeeID.ActualFieldName].ToString();
                        CurLogItem.ClaimantCompany = ResultRow[this.DataStructure.Views.GeneralActionHistory.ClaimantCompany.ActualFieldName].ToString();
                        CurLogItem.ApproverEmployeeID = ResultRow[this.DataStructure.Views.GeneralActionHistory.ApproverEmployeeID.ActualFieldName].ToString();

                        ResultCollection.Add(CurLogItem);
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetAllGeneralLog] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultCollection;
        }

        #endregion

        #endregion

        #region Actions

        #region LogMessage
        public bool LogMessage(string Content, SystemUser CurrentUser, LogInterface Interface)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.Interface.ActualFieldName, Interface.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.Description.ActualFieldName, Content.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.LogBy.ActualFieldName, CurrentUser.InternalID));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.ActionsLog.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }
        //FRANK create this functions for audit log enhencement 27-JAN-2013
        public bool LogMessageFull(string Content, SystemUser CurrentUser, LogInterface Interface,
            string UserID, string ClaimantID, string RoleID, string Action, string ApproverID, string DfltCurrency, string CreditCardNo,
            string AprStopPoint, string AprLimit, string NoAprRq, string NoAuthorizerRq, string AprRoute, string AsClaimant,
            string AsReviewer, string LDAPAddress, double AprRangeFr, double AprRangeTo, string LogType, string AprLevel)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.Interface.ActualFieldName, Interface.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.Description.ActualFieldName, Content.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.LogBy.ActualFieldName, CurrentUser.InternalID));
                //FRANK additional fields jan-2013
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.UserID.ActualFieldName, UserID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.ClaimantID.ActualFieldName, ClaimantID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.Action.ActualFieldName, Action));

                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.RoleID.ActualFieldName, RoleID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.ApproverID.ActualFieldName, ApproverID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.DfltCurrency.ActualFieldName, DfltCurrency));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.CreditCardNo.ActualFieldName, CreditCardNo));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AprStopPoint.ActualFieldName, AprStopPoint));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AprLimit.ActualFieldName, AprLimit));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.NoAprRq.ActualFieldName, NoAprRq.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.NoAuthorizerRq.ActualFieldName, NoAprRq.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AprRoute.ActualFieldName, AprRoute));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AsClaimant.ActualFieldName, AsClaimant));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AsReviewer.ActualFieldName, AsReviewer));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.LDAPAddress.ActualFieldName, LDAPAddress));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AprRangeFr.ActualFieldName, AprRangeFr.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AprRangeTo.ActualFieldName, AprRangeTo.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.LogType.ActualFieldName, LogType));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.AprLevel.ActualFieldName, AprLevel));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.ActionsLog.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }
        #endregion

        #region LogError
        public bool LogError(string LogID, string Content, SystemUser CurrentUser, LogInterface Interface)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                Params.Add(new DatabaseParameter(DataStructure.Tables.ErrorLog.LogID.ActualFieldName, LogID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ErrorLog.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionsLog.Interface.ActualFieldName, Interface.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ErrorLog.Description.ActualFieldName, Content.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ErrorLog.LogBy.ActualFieldName, CurrentUser.InternalID));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.ErrorLog.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }

        public bool LogError(string Content, SystemUser CurrentUser, LogInterface Interface)
        {
            return this.LogError(SwissArmy.UniqueID(), Content, CurrentUser, Interface);
        }
        #endregion

        #region LogAction
        public bool LogAction(string ClaimID, string UserID, string Action, GonzalesClaimHeader.TypeOfClaimStatus ActionStatus)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionHistory.ClaimID.ActualFieldName, ClaimID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionHistory.PersonnelID.ActualFieldName, UserID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionHistory.Action.ActualFieldName, Action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionHistory.ActionDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.ActionHistory.ActionStatus.ActualFieldName, ClaimManager.GetClaimStatusInCode(ActionStatus).ToString() ));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.ActionHistory.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }
        #endregion

        #region ChangeLog...

        #region Log Authorizer
        public bool ChangeLogAuthorizer(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname, 
                                        string action, string entity_id, string user_id, int user_level, string user_approve_currency, decimal user_approve_min, 
                                        decimal user_approve_max, string loggedby_role, string userid_affected, string entity_authorizer
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.LogBy.ActualFieldName, logby.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.EmployeeName.ActualFieldName, employeename.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.CompanyName.ActualFieldName, companyname.Replace("'", "''")));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.UserEmployeeID.ActualFieldName, user_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.Level.ActualFieldName, user_level.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.Currency.ActualFieldName, user_approve_currency));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.MinAmount.ActualFieldName, user_approve_min.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.MaxAmount.ActualFieldName, user_approve_max.ToString()));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.UserIDAffected.ActualFieldName, userid_affected));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_Authorizer.Entity_Authorizer.ActualFieldName, entity_authorizer));
                
                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_Authorizer.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #region Log Change Exceptional Approver
        public bool ChangeLogExceptionalApprover(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname, 
            string action, string entity_id, string approver_id, int approving_level, string loggedby_role, string userid_affected, string user_id
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.LogBy.ActualFieldName, logby.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.EmployeeName.ActualFieldName, employeename.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.CompanyName.ActualFieldName, companyname.Replace("'", "''")));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.ApproverID.ActualFieldName, approver_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.ApprovingLevel.ActualFieldName, approving_level.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.UserIDAffected.ActualFieldName, userid_affected));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ExceptionalApprover.UserID.ActualFieldName, user_id));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_ExceptionalApprover.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #region Log Change FA
        public bool ChangeLogFinanceAdmin(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname,
                                        string action, string entity_id, string user_id, int IsFinancialManager, string loggedby_role, string userid_affected, string company_fa
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.LogBy.ActualFieldName, logby.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.EmployeeName.ActualFieldName, employeename.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.CompanyName.ActualFieldName, companyname.Replace("'", "''")));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.UserEmployeeID.ActualFieldName, user_id));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.IsFinancialManager.ActualFieldName, IsFinancialManager.ToString()));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.UserIDAffected.ActualFieldName, userid_affected));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceAdmin.CompanyFinanceAdmin.ActualFieldName, company_fa));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_FinanceAdmin.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #region Log Change FI
        public bool ChangeLogFinanceVerifier(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname,
            string action, string entity_id, string user_id, int user_level, string user_approve_currency, decimal user_approve_min, decimal user_approve_max, 
            string loggedby_role, string userid_affected, string company_fi, string entity_fi
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.LogBy.ActualFieldName, logby.Replace("'","''"), true ));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.EmployeeName.ActualFieldName, employeename.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.CompanyName.ActualFieldName, companyname.Replace("'", "''")));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.UserEmployeeID.ActualFieldName, user_id));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.Level.ActualFieldName, user_level.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.Currency.ActualFieldName, user_approve_currency));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.MinLimit.ActualFieldName, user_approve_min.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.MaxLimit.ActualFieldName, user_approve_max.ToString()));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.UserIDAffected.ActualFieldName, userid_affected));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.CompanyFI.ActualFieldName, company_fi));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_FinanceVerifier.EntityFI.ActualFieldName, entity_fi));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_FinanceVerifier.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #region Log Change System Admin
        public bool ChangeLogSystemAdmin(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname,
                                        string action, string entity_id, string user_id, int IsITAdmin, int IsPowerAdmin, string loggedby_role, string userid_affected
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.LogBy.ActualFieldName, logby.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.EmployeeName.ActualFieldName, employeename.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.CompanyName.ActualFieldName, companyname.Replace("'", "''")));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.UserEmployeeID.ActualFieldName, user_id));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.IsITAdmin.ActualFieldName, IsITAdmin.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.IsPowerAdmin.ActualFieldName, IsPowerAdmin.ToString()));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_SystemAdmin.UserIDAffected.ActualFieldName, userid_affected));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_SystemAdmin.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #region Log Change Claimant Details
        public bool ChangeLogClaimantDetails(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname,
            string action, string entity_id, string user_id,
            /*string userDisplayname, string userADDistinguishedName, string userEmail, */string userProfitCenter, string userOnbehalf, /*string userAppr,*/
            string userApprCur, decimal userApprLimit, int userApprStopbit, int userApprRouting, int userActive, int userNoAppr, int userNoAuth, string userLanguage, 
            string userDateFormat, /*string userTitle, string userGreeting,*/ string userDefaultCurrency, string userCreditcard, string userLdap, string userOnbehalfReview,
            string loggedby_role, string userid_affected
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);
                if (this.IsReady = this.CurDBEngine.Connect()) this.CurSQLFactory = new SQLFactory(this.DBType);
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.LogBy.ActualFieldName, logby.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.EmployeeName.ActualFieldName, employeename.Replace("'","''"), true ));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.CompanyName.ActualFieldName, companyname));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.UserEmployeeID.ActualFieldName, user_id));

                //Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userDisplayname.ActualFieldName, userDisplayname.Replace("'", "''") ));
                //Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userADDistinguishedName.ActualFieldName, userADDistinguishedName));
                //Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userEmail.ActualFieldName, userEmail));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userProfitCenter.ActualFieldName, userProfitCenter));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userOnbehalf.ActualFieldName, userOnbehalf));
                //Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userAppr.ActualFieldName, userAppr));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userApprCur.ActualFieldName, userApprCur));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userApprLimit.ActualFieldName, userApprLimit.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userApprStopbit.ActualFieldName, userApprStopbit.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userApprRouting.ActualFieldName, userApprRouting.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userActive.ActualFieldName, userActive.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userNoAppr.ActualFieldName, userNoAppr.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userNoAuth.ActualFieldName, userNoAuth.ToString()));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userLanguage.ActualFieldName, userLanguage));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userDateFormat.ActualFieldName, userDateFormat));
                //Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userTitle.ActualFieldName, userTitle));
                //Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userGreeting.ActualFieldName, userGreeting));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userDefaultCurrency.ActualFieldName, userDefaultCurrency));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userCreditcard.ActualFieldName, userCreditcard));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userLdap.ActualFieldName, userLdap));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.userOnbehalfReview.ActualFieldName, userOnbehalfReview));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimantDetails.UserIDAffected.ActualFieldName, userid_affected));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_ClaimantDetails.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #region Get Change Log All Modules
        public LogsCollection GetChangeLogAuthorizer(string entity_id, string companyid, DateTime fromDate, DateTime toDate)
        {
            LogsCollection ResultCollection = null;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);
                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();
                
                Params.Add(new DatabaseParameter(DataStructure.StoredProcedures.GetLogChange.para_EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.StoredProcedures.GetLogChange.para_CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.StoredProcedures.GetLogChange.para_FromLogDateTime.ActualFieldName, fromDate));
                Params.Add(new DatabaseParameter(DataStructure.StoredProcedures.GetLogChange.para_ToLogDateTime.ActualFieldName, toDate));

                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructure.StoredProcedures.GetLogChange.ActualTableName, Params);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultCollection = new LogsCollection();

                    if (ResultTable.Rows.Count > 0)
                    {

                        DataRow[] ResultRows = ResultTable.Select("", this.DataStructure.StoredProcedures.GetLogChange.LogDateTime.ActualFieldName);

                        foreach (DataRow ResultRow in ResultRows)
                        {
                            GetChangeLogItem CurChangeLogItem = new GetChangeLogItem();
                            CurChangeLogItem.Instance = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.Instance.ActualFieldName].ToString();
                            CurChangeLogItem.LogDate = Convert.ToDateTime(ResultRow[this.DataStructure.StoredProcedures.GetLogChange.LogDateTime.ActualFieldName]);
                            CurChangeLogItem.LoggedbyName = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.LoggedBy.ActualFieldName].ToString();
                            CurChangeLogItem.LoggedbyRole = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.LoggedByRole.ActualFieldName].ToString();
                            CurChangeLogItem.UserIDAffected = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.UserIDAffected.ActualFieldName].ToString();
                            CurChangeLogItem.EmployeeID = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.EmployeeCode.ActualFieldName].ToString();
                            //CurChangeLogItem.EmployeeName = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.EmployeeName.ActualFieldName].ToString();
                            CurChangeLogItem.EntityID = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.EntityID.ActualFieldName].ToString();
                            CurChangeLogItem.CompanyCode = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.CompanyCode.ActualFieldName].ToString();
                            //CurChangeLogItem.CompanyName = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.CompanyName.ActualFieldName].ToString();
                            CurChangeLogItem.Module = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.Module.ActualFieldName].ToString();
                            CurChangeLogItem.ChangedField = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.ChangedField.ActualFieldName].ToString();
                            CurChangeLogItem.Action = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.Action.ActualFieldName].ToString();
                            CurChangeLogItem.PreviousValue = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.PreviousValue.ActualFieldName].ToString();
                            CurChangeLogItem.NewValue = ResultRow[this.DataStructure.StoredProcedures.GetLogChange.NewValue.ActualFieldName].ToString();
                            ResultCollection.Add(CurChangeLogItem);
                        }
                    }
                    else
                    {
                        this.ErrMsg = "No data.";
                    }
                }
                else
                {
                    this.ErrMsg = "[LogManager.GetAllGeneralLog] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            return ResultCollection;
        }
        #endregion

        #region Log Change Claim to Process by Reasons (Purpose)
        public bool ChangeLogClaim2ProcessByReasons(string logby_id, string logby, string employeeid, string employeename, string companyid, string companycode, string companyname,
                                        string action, string entity_id, string user_id, string claim_id, string reasons, string loggedby_role, string userid_affected
        )
        {
            bool smooth = false;
            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }
            }

            if (this.IsReady)
            {
                DatabaseParameters Params = new DatabaseParameters();

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.LogDateTime.ActualFieldName, DateTime.Now));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.LogByID.ActualFieldName, logby_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.LogBy.ActualFieldName, logby.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.EmployeeID.ActualFieldName, employeeid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.EmployeeName.ActualFieldName, employeename.Replace("'", "''"), true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.CompanyID.ActualFieldName, companyid));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.CompanyCode.ActualFieldName, companycode));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.CompanyName.ActualFieldName, companyname.Replace("'", "''")));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.Action.ActualFieldName, action));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.EntityID.ActualFieldName, entity_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.UserEmployeeID.ActualFieldName, user_id));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.ClaimID.ActualFieldName, claim_id));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.ClaimReasons.ActualFieldName, reasons.Replace("'", "''"), true));

                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.LoggedByRole.ActualFieldName, loggedby_role));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogChange_ClaimHeaderOnReasons.UserIDAffected.ActualFieldName, userid_affected));

                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogChange_ClaimHeaderOnReasons.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }
            }
            return smooth;
        }
        #endregion

        #endregion

        #region CreateLogApproverClaimAction
        public bool CreateLogApproverClaimAction(string ClaimID, string ApprInternalID, string ApprDisplayName, string ApprStatus)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.ClaimInternalID.ActualFieldName, ClaimID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr1_InternalID.ActualFieldName, ApprInternalID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr1_DisplayName.ActualFieldName, ApprDisplayName.Replace("'","''"),true, true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr1_Status.ActualFieldName, ApprStatus));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr1_Date.ActualFieldName, DateTime.Now));
               
                this.CurSQLFactory.InsertCommand(Params, DataStructure.Tables.LogClaimAction.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }

        #endregion

        #region UpdateLogApproverClaimAction
        public bool UpdateLogApproverClaimAction(string ClaimID, string ApprInternalID, string ApprDisplayName, string ApprStatus, string ApprLevel)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                DatabaseParameters keys = new DatabaseParameters();

                keys.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.ClaimInternalID.ActualFieldName, ClaimID));

                if (ApprLevel.CompareTo("1") == 0)
                {
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr2_InternalID.ActualFieldName, ApprInternalID));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr2_DisplayName.ActualFieldName, ApprDisplayName.Replace("'","''"),true, true));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr2_Status.ActualFieldName, ApprStatus));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr2_Date.ActualFieldName, DateTime.Now));
                }
                else if (ApprLevel.CompareTo("2") == 0)
                {
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr3_InternalID.ActualFieldName, ApprInternalID));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr3_DisplayName.ActualFieldName, ApprDisplayName.Replace("'","''"), true, true));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr3_Status.ActualFieldName, ApprStatus));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr3_Date.ActualFieldName, DateTime.Now));
                }
                else if (ApprLevel.CompareTo("3") == 0)
                {
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr4_InternalID.ActualFieldName, ApprInternalID));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr4_DisplayName.ActualFieldName, ApprDisplayName.Replace("'","''"), true, true));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr4_Status.ActualFieldName, ApprStatus));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr4_Date.ActualFieldName, DateTime.Now));
                }
                else if (ApprLevel.CompareTo("4") == 0)
                {
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr5_InternalID.ActualFieldName, ApprInternalID));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr5_DisplayName.ActualFieldName, ApprDisplayName.Replace("'", "''"), true, true));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr5_Status.ActualFieldName, ApprStatus));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr5_Date.ActualFieldName, DateTime.Now));
                }
                else if (ApprLevel.CompareTo("5") == 0)
                {
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr6_InternalID.ActualFieldName, ApprInternalID));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr6_DisplayName.ActualFieldName, ApprDisplayName.Replace("'", "''"), true, true));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr6_Status.ActualFieldName, ApprStatus));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr6_Date.ActualFieldName, DateTime.Now));
                }
                else if (ApprLevel.CompareTo("6") == 0)
                {
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr7_InternalID.ActualFieldName, ApprInternalID));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr7_DisplayName.ActualFieldName, ApprDisplayName.Replace("'", "''"), true, true));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr7_Status.ActualFieldName, ApprStatus));
                    Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Appr7_Date.ActualFieldName, DateTime.Now));
                }


                this.CurSQLFactory.UpdateCommand(keys, Params, DataStructure.Tables.LogClaimAction.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }

        #endregion

        #region UpdateLogAuthorizerClaimAction
        public bool UpdateLogAuthorizerClaimAction(string ClaimID, string AuthorizerInternalID, string AuthorizerDisplayName, string AuthorizerStatus)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                DatabaseParameters keys = new DatabaseParameters();

                keys.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.ClaimInternalID.ActualFieldName, ClaimID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Authorizer_InternalID.ActualFieldName, AuthorizerInternalID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Authorizer_DisplayName.ActualFieldName, AuthorizerDisplayName.Replace("'", "''"), true, true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Authorizer_Status.ActualFieldName, AuthorizerStatus));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.Authorizer_Date.ActualFieldName, DateTime.Now));

               

                this.CurSQLFactory.UpdateCommand(keys, Params, DataStructure.Tables.LogClaimAction.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }

        #endregion

        #region UpdateLogFAClaimAction
        public bool UpdateLogFAClaimAction(string ClaimID, string FAInternalID, string FADisplayName, string FAStatus)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                DatabaseParameters keys = new DatabaseParameters();

                keys.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.ClaimInternalID.ActualFieldName, ClaimID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fa_InternalID.ActualFieldName, FAInternalID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fa_DisplayName.ActualFieldName, FADisplayName.Replace("'", "''"), true, true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fa_Status.ActualFieldName, FAStatus));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fa_Date.ActualFieldName, DateTime.Now));



                this.CurSQLFactory.UpdateCommand(keys, Params, DataStructure.Tables.LogClaimAction.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }

        #endregion

        #region UpdateLogFVClaimAction
        public bool UpdateLogFVClaimAction(string ClaimID, string FVInternalID, string FVDisplayName, string FVStatus)
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {

                DatabaseParameters Params = new DatabaseParameters();
                DatabaseParameters keys = new DatabaseParameters();

                keys.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.ClaimInternalID.ActualFieldName, ClaimID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fv_InternalID.ActualFieldName, FVInternalID));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fv_DisplayName.ActualFieldName, FVDisplayName.Replace("'", "''"), true, true));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fv_Status.ActualFieldName, FVStatus));
                Params.Add(new DatabaseParameter(DataStructure.Tables.LogClaimAction.fv_Date.ActualFieldName, DateTime.Now));



                this.CurSQLFactory.UpdateCommand(keys, Params, DataStructure.Tables.LogClaimAction.ActualTableName);
                string sql = this.CurSQLFactory.SQL;

                try
                {
                    this.CurDBEngine.ExecuteQuery(sql);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }

            return smooth;
        }

        #endregion

        #region ClearErrorLog
        public bool ClearErrorLog()
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();

                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructure.Tables.ErrorLog.ActualTableName);

                try
                {
                    this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }
            return smooth;
        }
        #endregion

        #region ClearGeneralActionLog
        public bool ClearGeneralActionLog()
        {
            bool smooth = false;

            if (!this.IsReady)
            {
                this.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn);

                if (this.IsReady = this.CurDBEngine.Connect())
                {
                    this.CurSQLFactory = new SQLFactory(this.DBType);
                }

            }

            if (this.IsReady)
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();

                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructure.Tables.ActionsLog.ActualTableName);

                try
                {
                    this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                    smooth = true;
                }
                catch (Exception ex)
                {
                    smooth = false;
                    this.ErrMsg = ex.Message;
                }

            }
            return smooth;
        }
        #endregion

        #endregion

        public void Dispose()
        {
            this.CurDBEngine = null;
        }
    }
    
    
}
